﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectManager : UnitySingleton<ObjectManager>
{

    private Dictionary<uint, GameObject> dicGameObject;
    private Dictionary<uint, uint> dicRoot;
    private uint _objID;

	public override void Init()
    {
        dicGameObject = new Dictionary<uint, GameObject>();
        dicRoot = new Dictionary<uint, uint>();
    }


    public uint AddObj(GameObject obj)
    {
        if(obj == null)
        {
            Debug.LogError("对象为空.....");
            return 0;
        }
        ++_objID;
        dicGameObject.Add(_objID, obj);
        return _objID;
    }

    public void RemoveObj(uint objID)
    {
        GameObject obj = null;
        if(dicGameObject.TryGetValue(objID,out obj))
        {
            dicGameObject.Remove(objID);
            Destroy(obj);
        }
    }



    /// <summary>
    /// 获取组件对象
    /// </summary>
    /// <param name="objID"></param>
    /// <returns></returns>
    public GameObject GetGameObject(uint objID)
    {
        GameObject obj = null;
        if (dicGameObject.TryGetValue(objID, out obj))
        {
            return obj;
        }
        return null;
    }

}



